package com.goushu.service.impl;

import com.goushu.mapper.CartMapper;
import com.goushu.pojo.Cart;
import com.goushu.service.CartService;
import com.goushu.utils.ThreadLocalUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class CartServiceImpl implements CartService {

    @Autowired
    private CartMapper cartMapper;

    @Override
    public List<Cart> listCart() {
        Map<String, Object> map = ThreadLocalUtil.get();
        Integer cId = (Integer) map.get("id");
        return cartMapper.listCart(cId);
    }

    @Override
    public void addCart(Integer id, Integer count) {
        Map<String, Object> map = ThreadLocalUtil.get();
        Integer cId = (Integer) map.get("id");
        cartMapper.addCart(id, count, cId);
    }

    @Override
    public Cart checkCartExist(Integer id) {
        Map<String, Object> map = ThreadLocalUtil.get();
        Integer cId = (Integer) map.get("id");
        return cartMapper.checkCartExist(id, cId);
    }

    @Override
    public void modifyCart(Cart cart) {
        cartMapper.modifyCart(cart);
    }

    @Override
    public void deleteCart(Integer id) {
        cartMapper.deleteCart(id);
    }

    @Override
    public void updateCount(Integer id, Integer count) {
        Map<String, Object> map = ThreadLocalUtil.get();
        Integer cId = (Integer) map.get("id");
        cartMapper.updateCount(id, count, cId);
    }

    @Override
    public void deleteCartByBId(Integer bId) {
        Map<String, Object> map = ThreadLocalUtil.get();
        Integer cId = (Integer) map.get("id");
        cartMapper.deleteCartByBId(bId, cId);
    }

}
